package com.jservice.api.service.smk;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jservice.api.dto.Request;
import com.jservice.api.dto.Response;
import com.jservice.api.dto.ResponseHeader;
import com.jservice.api.service.BaseService;
import com.jservice.api.service.IService;
import com.jservice.model.SmkAd;
import com.jservice.model.SmkBanner;
import com.jservice.model.SmkNews;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Smk0010 - 首页 所有数据
 *
 * @Author cwledit
 * @DATE 2017/6/17.
 */
@Service("smk0010")
public class Smk0010 extends BaseService implements IService{
    @Override
    public Response excute(Request request, Response response, ResponseHeader header, String method) throws Exception {
        Map result = new HashMap();
        String sql = "select sn.icon_url, sn.title,sn.sub_title, sn.id from "+ SmkNews.TABLE_NAME+" sn where sn.status = 'ONLINE' order by orders desc," +
                " create_date desc";
        Record record = Db.findFirst(sql);
        result.put("top",record);
        List<SmkBanner> bannerList = SmkBanner.dao.doFind("status = ? order by orders desc, create_date desc ","ONLINE");
        result.put("banners",bannerList);
        List<SmkAd> adList = SmkAd.dao.doFind("status = ?  order by orders desc, create_date desc ","ONLINE");
        result.put("ads",adList);
        return renderSUC(result,response,header);
    }
}
